home *** CD-ROM | disk | FTP | other *** search
- /******************************************************************************
- ** **
- ** Module: BoxPaint_cursor3d.c **
- ** **
- ** **
- ** Purpose: Contains code to create and manipulate a 3D cursor. **
- ** **
- ** Author: Michael Bishop **
- ** **
- ** **
- ** Copyright (C) 1996-1997 Apple Computer, Inc. All rights reserved. **
- ** **
- ** **
- *****************************************************************************/
-
- #include <Memory.h>
- #include <assert.h>
-
- #include "QD3D.h"
- #include "QD3DGroup.h"
- #include "QD3DGeometry.h"
- #include "QD3DMath.h"
- #include "QD3DTransform.h"
- #include "QD3DShader.h"
-
- #include "BoxPaint_cursor3d.h"
- #include "BoxPaint_Support.h"
- #include "BoxPaint_utility.h"
-
-
- /******************************************************************************
- ** **
- ** STRUCTURES **
- ** **
- ** Comments: IF YOU CHANGE THIS, UPDATE Cursor3D_Init, _Dispose, **
- ** and_New !!!!!!!!!!! **
- ** **
- *****************************************************************************/
-
- struct _cursor3d {
- TQ3Boolean fShowOrientation; /* to show the direction the
- cursor is pointing */
- TQ3GroupObject fCursorModel; /* the Cursor Shape */
- TQ3GroupObject fOrientationModel; /* the orientation indicator*/
- Cursor3DPlacement fCursorPlacement; /* Where is the cursor? */
- TQ3Matrix4x4 fTransform; /* Local to World space */
- TQ3Vector3D fScale; /* the relative size */
- TQ3AttributeSet fCursorAttributeSet;/* Attributes for the whole
- cursor */
- } ;
-
- /******************************************************************************
- ** **
- ** Local functions **
- ** **
- *****************************************************************************/
-
- static void Cursor3D_Init(
- Cursor3DHdl theCursor3D);
-
- static void Cursor3D_InitPlacement(
- Cursor3DPlacement *theCursor3DPlacement);
-
- static void Cursor3D_EnableBounding(
- Cursor3DHdl theCursor3D);
-
- static void Cursor3D_DisableBounding(
- Cursor3DHdl theCursor3D);
-
- static void Cursor3D_Scale(
- Cursor3DHdl theCursor3D,
- float theScale);
-
- static TQ3DisplayGroupObject Cursor3D_NewDefaultCursor(
- void);
-
- static TQ3DisplayGroupObject Cursor3D_NewDefaultOrientationModel(
- void);
-
-
- /*===========================================================================*\
- *
- * Routine: Cursor3D_New()
- *
- * Comments:
- *
- \*===========================================================================*/
-
- Cursor3DHdl Cursor3D_New(TQ3GroupObject theModel)
- {
- Cursor3DHdl theCursor3D;
- TQ3DisplayGroupState theState;
- TQ3ColorRGB theColor;
-
- /*
- ** Allocate the memory
- */
-
- if (( theCursor3D = (Cursor3DHdl)Utility_MemoryNew(sizeof(Cursor3D))) != NULL)
- {
- Cursor3D_Init(theCursor3D);
-
-
- /**************************************
- ** **
- ** fCursorModel **
- ** **
- **************************************/
-
- /*
- ** If we were passed in a model
- */
-
- if ( theModel != NULL )
- {
- /*
- ** Add it to our group
- ** NOTE: we add it instead of assigning it to fCursorModel
- ** because we may want to set flags or otherwise affect our
- ** group object without affecting the original, passed-in model
- */
-
- /*
- ** Allocate the cursor
- */
- (**theCursor3D).fCursorModel = Q3DisplayGroup_New();
- if ((**theCursor3D).fCursorModel == NULL)
- goto bail;
-
- if ( Q3Group_AddObject((**theCursor3D).fCursorModel, theModel) != NULL )
- goto bail;
- }
- /*
- ** Otherwise, add our default model
- */
-
- else {
- (**theCursor3D).fCursorModel = Cursor3D_NewDefaultCursor();
- if ((**theCursor3D).fCursorModel == NULL)
- goto bail;
- }
-
- /*
- ** We want to set some state variables for the cursor so get
- ** the state of the fCursorModel so we can preserve whatever's
- ** already there
- */
- Q3DisplayGroup_GetState((**theCursor3D).fCursorModel, &theState);
-
- /*
- ** we don't want the cursor to be picked
- */
-
- theState = theState & ~(kQ3DisplayGroupStateMaskIsPicked);
-
- /*
- ** We inline the cursor because the group is basically just
- ** being used to hold geometries and not attributes. When a
- ** group is submitted, the stack is pushed and then popped
- ** afterwards. Since there is no reason for us to push and pop
- ** the stack, we inline it, which prevents that from occurring.
- ** Keep in mind that any attributes in this group will be held
- ** over for the next group (ie. any thing submitted after the
- ** cursor will be transparent unless the stack is popped
- */
- theState = theState | (kQ3DisplayGroupStateMaskIsInline);
-
- Q3DisplayGroup_SetState((**theCursor3D).fCursorModel, theState);
-
-
-
-
- /**************************************
- ** **
- ** fOrientationModel **
- ** **
- **************************************/
-
- /*
- ** Allocate the orientation
- */
- (**theCursor3D).fOrientationModel = Cursor3D_NewDefaultOrientationModel();
- if ((**theCursor3D).fOrientationModel != NULL)
- {
- /*
- ** Don't bail, we can live with no orientation model
- ** Now, get the state of the orientation model
- */
-
- Q3DisplayGroup_GetState((**theCursor3D).fOrientationModel, &theState);
-
- /*
- ** we don't want the orientation to be picked
- */
-
- theState = theState & ~(kQ3DisplayGroupStateMaskIsPicked);
- theState = theState | (kQ3DisplayGroupStateMaskIsInline);
-
- Q3DisplayGroup_SetState((**theCursor3D).fOrientationModel, theState);
-
- }
-
-
- /**************************************
- ** **
- ** fCursorAttributeSet **
- ** **
- **************************************/
-
- /*
- ** Make the cursor transparent
- */
- (**theCursor3D).fCursorAttributeSet = Q3AttributeSet_New ();
-
- if ((**theCursor3D).fCursorAttributeSet != NULL)
- {
- theColor.r = theColor.g = theColor.b = 0.35 ;
-
- Q3AttributeSet_Add ((**theCursor3D).fCursorAttributeSet,
- kQ3AttributeTypeTransparencyColor,
- &theColor);
- }
-
-
- /*
- ** Finally, we don't want the cursor to be included in bounding
- ** operations
- */
- Cursor3D_DisableBounding(theCursor3D);
-
- }
-
- return theCursor3D;
-
- bail:
- Cursor3D_Dispose(theCursor3D);
- return NULL;
-
- }
-
-
- /*===========================================================================*\
- *
- * Routine: Cursor3D_Dispose()
- *
- * Comments: Cleans up and deallocates memory.
- *
- \*===========================================================================*/
-
- TQ3Status Cursor3D_Dispose(Cursor3DHdl theCursor3D)
- {
- assert(theCursor3D != NULL);
- assert(*theCursor3D != NULL);
-
- if ((**theCursor3D).fCursorModel != NULL)
- Q3Object_Dispose((**theCursor3D).fCursorModel);
-
- if ((**theCursor3D).fOrientationModel != NULL)
- Q3Object_Dispose((**theCursor3D).fOrientationModel);
-
- if ((**theCursor3D).fCursorAttributeSet != NULL)
- Q3Object_Dispose((**theCursor3D).fCursorAttributeSet);
-
- DisposeHandle((Handle)theCursor3D);
-
- return kQ3Success;
- }
-
-
- /*===========================================================================*\
- *
- * Routine: Cursor3D_Show()
- *
- * Comments:
- *
- \*===========================================================================*/
-
- void Cursor3D_Show(Cursor3DHdl theCursor3D)
- {
- TQ3DisplayGroupState theState;
-
- assert(theCursor3D != NULL);
- assert(*theCursor3D != NULL);
-
- /*
- ** Get the original Flags
- */
- Q3DisplayGroup_GetState((**theCursor3D).fCursorModel, &theState);
-
- /*
- ** we want the cursor to be drawn
- */
- theState = theState | ( kQ3DisplayGroupStateMaskIsDrawn);
-
- Q3DisplayGroup_SetState((**theCursor3D).fCursorModel, theState);
-
- /*
- ** Same thing for fOrientationModel
- */
- Q3DisplayGroup_GetState((**theCursor3D).fOrientationModel, &theState);
- theState = theState | ( kQ3DisplayGroupStateMaskIsDrawn);
- Q3DisplayGroup_SetState((**theCursor3D).fOrientationModel, theState);
- }
-
-
- /*===========================================================================*\
- *
- * Routine: Cursor3D_Hide()
- *
- * Comments:
- *
- \*===========================================================================*/
-
- void Cursor3D_Hide(Cursor3DHdl theCursor3D)
- {
- TQ3DisplayGroupState theState;
-
- assert(theCursor3D != NULL);
- assert(*theCursor3D != NULL);
-
- /*
- ** See Cursor3D_Show
- */
- Q3DisplayGroup_GetState((**theCursor3D).fCursorModel, &theState);
- theState = theState & ~(kQ3DisplayGroupStateMaskIsDrawn);
- Q3DisplayGroup_SetState((**theCursor3D).fCursorModel, theState);
-
- Q3DisplayGroup_GetState((**theCursor3D).fOrientationModel, &theState);
- theState = theState & ~(kQ3DisplayGroupStateMaskIsDrawn);
- Q3DisplayGroup_SetState((**theCursor3D).fOrientationModel, theState);
- }
-
-
- /*===========================================================================*\
- *
- * Routine: Cursor3D_SetPlacement()
- *
- * Comments: Sets the Cursor to whereever you want. Input MUST be
- * normalized
- *
- \*===========================================================================*/
-
- TQ3Status Cursor3D_SetPlacement(
- Cursor3DHdl theCursor3D,
- Cursor3DPlacement *theCursor3DPlacement)
- {
- TQ3Matrix4x4 theMatrix4x4;
- TQ3Vector3D theXAxis;
-
- assert(theCursor3D != NULL);
- assert(*theCursor3D != NULL);
-
- Q3Matrix4x4_SetIdentity(&theMatrix4x4);
-
- /*
- ** Get the last vector we need
- */
- Q3Vector3D_Cross( (const TQ3Vector3D *)&theCursor3DPlacement->up,
- (const TQ3Vector3D *) &theCursor3DPlacement->toward,
- &theXAxis);
-
- /*
- ** This is a neat graphics trick stuff the normals into the matrix and
- ** it will automatically place your cursor with all the correct
- ** orientation
- */
-
- theMatrix4x4.value[0][0] = theXAxis.x;
- theMatrix4x4.value[0][1] = theXAxis.y;
- theMatrix4x4.value[0][2] = theXAxis.z;
-
- theMatrix4x4.value[1][0] = theCursor3DPlacement->up.x;
- theMatrix4x4.value[1][1] = theCursor3DPlacement->up.y;
- theMatrix4x4.value[1][2] = theCursor3DPlacement->up.z;
-
- theMatrix4x4.value[2][0] = theCursor3DPlacement->toward.x;
- theMatrix4x4.value[2][1] = theCursor3DPlacement->toward.y;
- theMatrix4x4.value[2][2] = theCursor3DPlacement->toward.z;
-
- /*
- ** Stuff in the translation too
- */
- theMatrix4x4.value[3][0] = theCursor3DPlacement->cursorLocation.x;
- theMatrix4x4.value[3][1] = theCursor3DPlacement->cursorLocation.y;
- theMatrix4x4.value[3][2] = theCursor3DPlacement->cursorLocation.z;
-
- (**theCursor3D).fTransform = theMatrix4x4;
-
- return kQ3Success;
-
- }
-
-
- /*===========================================================================*\
- *
- * Routine: Cursor3D_Submit()
- *
- * Comments:
- *
- \*===========================================================================*/
-
- TQ3Status Cursor3D_Submit(
- Cursor3DPtr theCursor3D,
- TQ3ViewObject theView)
- {
- assert(theCursor3D != NULL);
-
- if (
- Q3AttributeSet_Submit ( theCursor3D->fCursorAttributeSet, theView )
- == kQ3Failure) goto bail;
-
- if(
- Q3MatrixTransform_Submit( &theCursor3D->fTransform, theView)
- == kQ3Failure) goto bail;
-
- if (
- Q3ScaleTransform_Submit ( &theCursor3D->fScale, theView )
- == kQ3Failure) goto bail;
-
- if (
- Q3DisplayGroup_Submit( theCursor3D->fOrientationModel, theView)
- == kQ3Failure) goto bail;
-
- if (
- Q3DisplayGroup_Submit( theCursor3D->fCursorModel, theView)
- == kQ3Failure) goto bail;
-
- return kQ3Success;
-
- bail:
- return kQ3Failure;
- }
-
-
- /*===========================================================================*\
- *
- * Routine: Cursor3D_ChangeSizeAgainstGroup()
- *
- * Comments: Scales the cursor with respect to a model. Useful to change
- * cursor size depending on what it acts upon.
- *
- \*===========================================================================*/
-
- TQ3Status Cursor3D_ChangeSizeAgainstGroup(
- Cursor3DHdl theCursor3D,
- TQ3DisplayGroupObject theModel,
- TQ3ViewObject theView,
- float theScale)
- {
- TQ3ViewStatus theViewStatus;
- TQ3BoundingBox cursorBBox, groupBBox;
- float theRatio;
-
- assert(theCursor3D != NULL);
- assert(*theCursor3D != NULL);
- assert(theModel != NULL);
- assert(theView != NULL);
-
- /*
- ** For the purpose of this, we want to enable bounding
- */
- Cursor3D_EnableBounding(theCursor3D);
-
- /*
- ** Get the two bounding boxes
- */
- if (
- Q3View_StartBoundingBox ( theView, kQ3ComputeBoundsExact )
- != kQ3Failure)
- {
- do {
- Q3DisplayGroup_Submit( (**theCursor3D).fCursorModel, theView) ;
- } while(
- (theViewStatus = Q3View_EndBoundingBox( theView, &cursorBBox ))
- == kQ3ViewStatusRetraverse );
- }
-
- /*
- ** This has to be completed for this routine
- */
- else goto bail;
-
-
-
- if (
- Q3View_StartBoundingBox ( theView, kQ3ComputeBoundsExact )
- != kQ3Failure)
- {
- do {
- Q3DisplayGroup_Submit( theModel, theView);
- } while(
- (theViewStatus = Q3View_EndBoundingBox( theView, &groupBBox ))
- == kQ3ViewStatusRetraverse );
- }
- /*
- ** This has to be completed for this routine
- */
- else goto bail;
-
-
- /*
- ** Make sure there's stuff in it
- */
- if ((cursorBBox.isEmpty == kQ3False) && (groupBBox.isEmpty == kQ3False) ) {
- /*
- ** Compute the ratio
- */
- theRatio = ((Q3Point3D_Distance((const TQ3Point3D *)&groupBBox.min,
- (const TQ3Point3D *)&groupBBox.max))
- /
- (Q3Point3D_Distance((const TQ3Point3D *)&cursorBBox.min,
- (const TQ3Point3D *)&cursorBBox.max)));
- } else goto bail;
-
- /*
- ** We scale it to match the model and then scale it based on
- ** the parameter
- */
- theRatio = theRatio * theScale;
-
- Cursor3D_Scale(theCursor3D, theRatio);
-
- /*
- ** Don't forget to disable it when we are done
- */
- Cursor3D_DisableBounding(theCursor3D);
- return kQ3Success;
-
- bail:
- /*
- ** Don't forget to disable it when we are done
- */
- Cursor3D_DisableBounding(theCursor3D);
- return kQ3Failure;
-
- }
-
-
-
- /******************************************************************************
- ** **
- ** PRIVATE FUNCTIONS **
- ** **
- *****************************************************************************/
-
- /*===========================================================================*\
- *
- * Routine: Cursor3D_Init()
- *
- * Comments:
- *
- \*===========================================================================*/
-
- static void Cursor3D_Init(Cursor3DHdl theCursor3D)
- {
- assert(theCursor3D != NULL);
- assert(*theCursor3D != NULL);
-
- /*
- ** don't show orientation
- */
-
- (**theCursor3D).fShowOrientation = kQ3False;
-
- /*
- ** no model yet
- */
-
- (**theCursor3D).fCursorModel = NULL;
-
- /*
- ** Set up the placement (most likely, the origin)
- */
-
- Cursor3D_InitPlacement(&(**theCursor3D).fCursorPlacement);
-
- /*
- ** no transform
- */
-
- Q3Matrix4x4_SetIdentity(&(**theCursor3D).fTransform);
-
-
- /*
- ** no scale
- */
-
- (**theCursor3D).fScale.x =
- (**theCursor3D).fScale.y =
- (**theCursor3D).fScale.z = 1.0;
-
- /*
- ** no attributes
- */
-
- (**theCursor3D).fCursorAttributeSet = NULL;
- }
-
- /*===========================================================================*\
- *
- * Routine: Cursor3D_InitPlacement()
- *
- * Comments:
- *
- \*===========================================================================*/
-
- static void Cursor3D_InitPlacement(Cursor3DPlacement *theCursor3DPlacement)
- {
- Q3Point3D_Set(&theCursor3DPlacement->cursorLocation, 0.0, 0.0, 0.0);
- Q3Vector3D_Set(&theCursor3DPlacement->toward, 0.0, 0.0, 1.0);
- Q3Vector3D_Set(&theCursor3DPlacement->up, 0.0, 1.0, 0.0);
- }
-
-
- /*===========================================================================*\
- *
- * Routine: Cursor3D_EnableBounding()
- *
- * Comments:
- *
- \*===========================================================================*/
-
- static void Cursor3D_EnableBounding(Cursor3DHdl theCursor3D)
- {
- TQ3DisplayGroupState theState;
-
- assert(theCursor3D != NULL);
- assert(*theCursor3D != NULL);
-
- Q3DisplayGroup_GetState((**theCursor3D).fCursorModel, &theState);
- theState = theState | ( kQ3DisplayGroupStateMaskUseBoundingBox |
- kQ3DisplayGroupStateMaskUseBoundingSphere);
- Q3DisplayGroup_SetState((**theCursor3D).fCursorModel, theState);
-
- Q3DisplayGroup_GetState((**theCursor3D).fOrientationModel, &theState);
- theState = theState | ( kQ3DisplayGroupStateMaskUseBoundingBox |
- kQ3DisplayGroupStateMaskUseBoundingSphere);
- Q3DisplayGroup_SetState((**theCursor3D).fOrientationModel, theState);
- }
-
-
- /*===========================================================================*\
- *
- * Routine: Cursor3D_DisableBounding()
- *
- * Comments:
- *
- \*===========================================================================*/
-
- static void Cursor3D_DisableBounding(Cursor3DHdl theCursor3D)
- {
- TQ3DisplayGroupState theState;
-
- assert(theCursor3D != NULL);
- assert(*theCursor3D != NULL);
-
- Q3DisplayGroup_GetState((**theCursor3D).fCursorModel, &theState);
- theState = theState & ~( kQ3DisplayGroupStateMaskUseBoundingBox |
- kQ3DisplayGroupStateMaskUseBoundingSphere);
- Q3DisplayGroup_SetState((**theCursor3D).fCursorModel, theState);
-
- Q3DisplayGroup_GetState((**theCursor3D).fOrientationModel, &theState);
- theState = theState & ~( kQ3DisplayGroupStateMaskUseBoundingBox |
- kQ3DisplayGroupStateMaskUseBoundingSphere);
- Q3DisplayGroup_SetState((**theCursor3D).fOrientationModel, theState);
- }
-
-
- /*===========================================================================*\
- *
- * Routine: Cursor3D_Scale()
- *
- * Comments:
- *
- \*===========================================================================*/
-
- static void Cursor3D_Scale( Cursor3DHdl theCursor3D,
- float theScale)
- {
- assert(theCursor3D != NULL);
- assert(*theCursor3D != NULL);
-
- Q3Vector3D_Set ( &(**theCursor3D).fScale, theScale, theScale, theScale ) ;
-
- }
-
-
- /*===========================================================================*\
- *
- * Routine: Cursor3D_NewDefaultCursor()
- *
- * Comments: Creates the default model for the cursor
- *
- \*===========================================================================*/
-
- static TQ3DisplayGroupObject Cursor3D_NewDefaultCursor(void)
- {
- TQ3DisplayGroupObject theModel = NULL,
- thePart = NULL;
- TQ3ShaderObject myIlluminationShader = NULL;
- TQ3StyleObject theStyleObject = NULL;
-
- TQ3ConeData theConeData;
- TQ3ColorRGB theColor;
- TQ3CylinderData theCylinderData;
- TQ3SubdivisionStyleData theSubdivisionStyleData;
-
- theModel = Q3DisplayGroup_New();
-
- /*
- ** Essential for this function to continue
- */
- if (!theModel) goto bail;
-
-
- myIlluminationShader = Q3LambertIllumination_New();
-
- if (myIlluminationShader) {
- Q3Group_AddObject(theModel, myIlluminationShader) ;
- Q3Object_Dispose(myIlluminationShader);
- myIlluminationShader = NULL;
- }
-
- /**************************************
- ** **
- ** HOW TO MAKE A PENCIL **
- ** **
- **************************************/
-
- theStyleObject = Q3InterpolationStyle_New(kQ3InterpolationStyleVertex);
-
- if (theStyleObject) {
- Q3Group_AddObject(theModel, theStyleObject) ;
- Q3Object_Dispose(theStyleObject);
- theStyleObject = NULL;
- }
-
- theSubdivisionStyleData.method = kQ3SubdivisionMethodConstant;
- theSubdivisionStyleData.c1 = 6;
- theSubdivisionStyleData.c2 = 1;
-
- theStyleObject = Q3SubdivisionStyle_New(&theSubdivisionStyleData);
- if (theStyleObject) {
- Q3Group_AddObject(theModel, theStyleObject) ;
- Q3Object_Dispose(theStyleObject);
- theStyleObject = NULL;
- }
-
-
- /**************************************
- ** **
- ** THE GRAPHITE **
- ** **
- **************************************/
-
- Q3Point3D_Set(&theConeData.origin, 0, 0, -1.0);
- Q3Vector3D_Set(&theConeData.orientation, 0, 0, 1.0);
- Q3Vector3D_Set(&theConeData.majorRadius, 0.26, 0.0, 0);
- Q3Vector3D_Set(&theConeData.minorRadius, 0.0, 0.26, 0);
- theConeData.uMin = 0.0; theConeData.uMax = 1.0;
- theConeData.vMin = 0.0; theConeData.vMax = 1.0;
- theConeData.caps = kQ3EndCapNone;
- theConeData.interiorAttributeSet = NULL;
- theConeData.bottomAttributeSet = NULL;
- theConeData.faceAttributeSet = NULL;
- theConeData.coneAttributeSet = Q3AttributeSet_New() ;
-
- theColor.r = 0.25; theColor.g = 0.25; theColor.b = 0.25;
-
- if (theConeData.coneAttributeSet) {
- Q3AttributeSet_Add (theConeData.coneAttributeSet,
- kQ3AttributeTypeDiffuseColor,
- &theColor);
- }
-
- thePart = Q3Cone_New(&theConeData);
-
- if (thePart) {
- Q3Group_AddObject(theModel, thePart) ;
- Q3Object_Dispose(thePart);
- thePart = NULL;
- }
-
- if (theConeData.coneAttributeSet) {
- Q3Object_Dispose(theConeData.coneAttributeSet);
- theConeData.coneAttributeSet = NULL;
- }
-
- /**************************************
- ** **
- ** THE WOOD **
- ** **
- **************************************/
-
- Q3Point3D_Set(&theConeData.origin, 0, 0, -2.0);
- Q3Vector3D_Set(&theConeData.orientation, 0, 0, 2.0);
- Q3Vector3D_Set(&theConeData.majorRadius, 0.5, 0.0, 0);
- Q3Vector3D_Set(&theConeData.minorRadius, 0.0, 0.5, 0);
- theConeData.uMin = 0.0; theConeData.uMax = 1.0;
- theConeData.vMin = 0.0; theConeData.vMax = 1.0;
- theConeData.caps = kQ3EndCapNone;
- theConeData.interiorAttributeSet = NULL;
- theConeData.bottomAttributeSet = NULL;
- theConeData.faceAttributeSet = NULL;
- theConeData.coneAttributeSet = Q3AttributeSet_New() ;
-
- theColor.r = 0.75; theColor.g = 0.75; theColor.b = 0.25;
-
- if (theConeData.coneAttributeSet) {
- Q3AttributeSet_Add (theConeData.coneAttributeSet,
- kQ3AttributeTypeDiffuseColor,
- &theColor);
- }
-
- thePart = Q3Cone_New(&theConeData);
-
- if (thePart) {
- Q3Group_AddObject(theModel, thePart) ;
- Q3Object_Dispose(thePart);
- thePart = NULL;
- }
-
- if (theConeData.coneAttributeSet) {
- Q3Object_Dispose(theConeData.coneAttributeSet);
- theConeData.coneAttributeSet = NULL;
- }
-
-
- /**************************************
- ** **
- ** THE ERASER **
- ** **
- **************************************/
-
- theSubdivisionStyleData.method = kQ3SubdivisionMethodConstant;
- theSubdivisionStyleData.c1 = 12;
- theSubdivisionStyleData.c2 = 1;
-
- theStyleObject = Q3SubdivisionStyle_New(&theSubdivisionStyleData);
-
- if (theStyleObject) {
- Q3Group_AddObject(theModel, theStyleObject) ;
- Q3Object_Dispose(theStyleObject);
- theStyleObject = NULL;
- }
-
- Q3Point3D_Set(&theCylinderData.origin, 0, 0, -7.0);
- Q3Vector3D_Set(&theCylinderData.orientation, 0, 0, 1.0);
- Q3Vector3D_Set(&theCylinderData.majorRadius, 0.48, 0.0, 0);
- Q3Vector3D_Set(&theCylinderData.minorRadius, 0.0, 0.48, 0);
- theCylinderData.uMin = 0.0; theCylinderData.uMax = 1.0;
- theCylinderData.vMin = 0.0; theCylinderData.vMax = 1.0;
- theCylinderData.caps = kQ3EndCapMaskBottom;
- theCylinderData.interiorAttributeSet = NULL;
- theCylinderData.topAttributeSet = NULL;
- theCylinderData.bottomAttributeSet = NULL;
- theCylinderData.faceAttributeSet = NULL;
- theCylinderData.cylinderAttributeSet = Q3AttributeSet_New() ;
-
- theColor.r = 1.0; theColor.g = 0.5; theColor.b = 0.5;
-
- if (theCylinderData.cylinderAttributeSet) {
- Q3AttributeSet_Add (theCylinderData.cylinderAttributeSet,
- kQ3AttributeTypeDiffuseColor,
- &theColor);
- }
-
- thePart = Q3Cylinder_New(&theCylinderData);
-
- if (thePart) {
- Q3Group_AddObject(theModel, thePart) ;
- Q3Object_Dispose(thePart);
- thePart = NULL;
- }
-
- if (theCylinderData.cylinderAttributeSet) {
- Q3Object_Dispose(theCylinderData.cylinderAttributeSet);
- theCylinderData.cylinderAttributeSet = NULL;
- }
-
- /**************************************
- ** **
- ** THE YELLOW PAINT **
- ** **
- **************************************/
-
- theSubdivisionStyleData.method = kQ3SubdivisionMethodConstant;
- theSubdivisionStyleData.c1 = 6;
- theSubdivisionStyleData.c2 = 1;
-
- theStyleObject = Q3SubdivisionStyle_New(&theSubdivisionStyleData);
- if (theStyleObject) {
- Q3Group_AddObject(theModel, theStyleObject) ;
- Q3Object_Dispose(theStyleObject);
- theStyleObject = NULL;
- }
-
- theStyleObject = Q3InterpolationStyle_New(kQ3InterpolationStyleNone);
- if (theStyleObject) {
- Q3Group_AddObject(theModel, theStyleObject) ;
- Q3Object_Dispose(theStyleObject);
- theStyleObject = NULL;
- }
-
- Q3Point3D_Set(&theCylinderData.origin, 0, 0, -6.0);
- Q3Vector3D_Set(&theCylinderData.orientation, 0, 0, 4.0);
- Q3Vector3D_Set(&theCylinderData.majorRadius, 0.5, 0.0, 0);
- Q3Vector3D_Set(&theCylinderData.minorRadius, 0.0, 0.5, 0);
- theCylinderData.uMin = 0.0; theCylinderData.uMax = 1.0;
- theCylinderData.vMin = 0.0; theCylinderData.vMax = 1.0;
- theCylinderData.caps = kQ3EndCapNone;
- theCylinderData.interiorAttributeSet = NULL;
- theCylinderData.topAttributeSet = NULL;
- theCylinderData.bottomAttributeSet = NULL;
- theCylinderData.faceAttributeSet = NULL;
- theCylinderData.cylinderAttributeSet = Q3AttributeSet_New() ;
-
- theColor.r = 1.0; theColor.g = 1.0; theColor.b = 0.0;
-
- if (theCylinderData.cylinderAttributeSet) {
- Q3AttributeSet_Add (theCylinderData.cylinderAttributeSet,
- kQ3AttributeTypeDiffuseColor,
- &theColor);
- }
-
- thePart = Q3Cylinder_New(&theCylinderData);
-
- if (thePart) {
- Q3Group_AddObject(theModel, thePart) ;
- Q3Object_Dispose(thePart);
- thePart = NULL;
- }
-
- if (theCylinderData.cylinderAttributeSet) {
- Q3Object_Dispose(theCylinderData.cylinderAttributeSet);
- theCylinderData.cylinderAttributeSet = NULL;
- }
-
- return theModel;
-
- bail:
- return NULL;
- }
-
-
- /*===========================================================================*\
- *
- * Routine: Cursor3D_NewDefaultOrientationModel()
- *
- * Comments: Creates the default orientation model
- *
- \*===========================================================================*/
-
- static TQ3DisplayGroupObject Cursor3D_NewDefaultOrientationModel(void)
- {
- TQ3DisplayGroupObject theModel = NULL,
- theLine = NULL;
- TQ3ShaderObject myIlluminationShader = NULL;
-
- TQ3ColorRGB theColor;
- TQ3LineData theLineData;
-
-
- /*
- ** theZOffsetAmount is needed to raise the lines alightly above the
- ** surface of what ever you're drawing on. Needed because if the lines
- ** were directly on the surface, they would disappear.
- */
-
- const float theZOffsetAmount = -0.1;
-
-
- theModel = Q3DisplayGroup_New();
-
- /*
- ** Essential for this function to continue
- */
- if (!theModel) goto bail;
-
- myIlluminationShader = Q3LambertIllumination_New();
-
- if (myIlluminationShader) {
- Q3Group_AddObject(theModel, myIlluminationShader) ;
- Q3Object_Dispose(myIlluminationShader);
- myIlluminationShader = NULL;
- }
-
- /**************************************
- ** **
- ** HOW TO CREATE **
- ** 3 SIMPLE LINES **
- ** **
- **************************************/
-
- /*
- ** The x, y, and z axis are colored r, g and b, respectively
- */
-
- /**************************************
- ** **
- ** X AXIS **
- ** **
- **************************************/
-
- theLineData.vertices[0].point.x = 0;
- theLineData.vertices[0].point.y = 0;
- theLineData.vertices[0].point.z = theZOffsetAmount;
- theLineData.vertices[0].attributeSet = NULL ;
-
- theLineData.vertices[1].point.x = 2.0;
- theLineData.vertices[1].point.y = 0.0;
- theLineData.vertices[1].point.z = theZOffsetAmount;
- theLineData.vertices[1].attributeSet = NULL ;
-
- theColor.r = 1.0;
- theColor.g = theColor.b = 0.75;
-
- theLineData.lineAttributeSet = Q3AttributeSet_New() ;
-
- if (theLineData.lineAttributeSet) {
- Q3AttributeSet_Add (theLineData.lineAttributeSet,
- kQ3AttributeTypeDiffuseColor,
- &theColor);
- }
-
- theLine = Q3Line_New(&theLineData);
-
- if (theLine) {
- Q3Group_AddObject(theModel, theLine) ;
- Q3Object_Dispose(theLine);
- theLine = NULL;
- }
-
- if (theLineData.lineAttributeSet) {
- Q3Object_Dispose(theLineData.lineAttributeSet);
- theLineData.lineAttributeSet = NULL;
- }
-
-
- /**************************************
- ** **
- ** Y AXIS **
- ** **
- **************************************/
-
- theLineData.vertices[0].point.x = 0;
- theLineData.vertices[0].point.y = 0;
- theLineData.vertices[0].point.z = theZOffsetAmount;
- theLineData.vertices[0].attributeSet = NULL ;
-
- theLineData.vertices[1].point.x = 0.0;
- theLineData.vertices[1].point.y = 2.0;
- theLineData.vertices[1].point.z = theZOffsetAmount;
- theLineData.vertices[1].attributeSet = NULL ;
-
-
- theColor.g = 1.0;
- theColor.r = theColor.b = 0.75;
-
- theLineData.lineAttributeSet = Q3AttributeSet_New();
-
- if (theLineData.lineAttributeSet) {
- Q3AttributeSet_Add (theLineData.lineAttributeSet,
- kQ3AttributeTypeDiffuseColor,
- &theColor);
- }
-
- theLine = Q3Line_New(&theLineData);
-
- if (theLine) {
- Q3Group_AddObject(theModel, theLine) ;
- Q3Object_Dispose(theLine);
- theLine = NULL;
- }
-
- if (theLineData.lineAttributeSet) {
- Q3Object_Dispose(theLineData.lineAttributeSet);
- theLineData.lineAttributeSet = NULL;
- }
-
- /**************************************
- ** **
- ** Z AXIS **
- ** **
- **************************************/
-
- theLineData.vertices[0].point.x = 0;
- theLineData.vertices[0].point.y = 0;
- theLineData.vertices[0].point.z = theZOffsetAmount;
- theLineData.vertices[0].attributeSet = NULL ;
-
- theLineData.vertices[1].point.x = 0.0;
- theLineData.vertices[1].point.y = 0.0;
- theLineData.vertices[1].point.z = -2.0;
- theLineData.vertices[1].attributeSet = NULL ;
-
- theColor.b = 1.0;
- theColor.g = theColor.r = 0.75;
-
- theLineData.lineAttributeSet = Q3AttributeSet_New();
-
- if (theLineData.lineAttributeSet) {
- Q3AttributeSet_Add (theLineData.lineAttributeSet,
- kQ3AttributeTypeDiffuseColor,
- &theColor);
- }
-
- theLine = Q3Line_New(&theLineData);
-
- if (theLine) {
- Q3Group_AddObject(theModel, theLine) ;
- Q3Object_Dispose(theLine);
- theLine = NULL;
- }
-
- if (theLineData.lineAttributeSet) {
- Q3Object_Dispose(theLineData.lineAttributeSet);
- theLineData.lineAttributeSet = NULL;
- }
-
- return theModel;
-
- bail:
- return NULL;
- }
-